package com.sunqizhong.mapper;

import com.sunqizhong.entity.Emp;
import com.sunqizhong.entity.EmpExpr;
import com.sunqizhong.entity.EmpQueryParam;
import org.apache.ibatis.annotations.*;
import org.w3c.dom.ls.LSInput;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {
    /*
    * 统计员工总记录数
    * */
/*
    @Select("select count(*) from emp")
    Long count();
*/

    /*
    * 分页查询
    * */
/*    @Select("select e.*,d.name deptName from emp e left join dept d on e.dept_id = d.id limit #{start},#{pageSize}")
    List<Emp> page(Integer start, Integer pageSize);*/

    /*
    * 列表查询
    * */
/*    @Select("select  e.*,d.name deptName from emp e left join dept d on e.dept_id = d.id")*/
    List<Emp> list(EmpQueryParam param);


    /*
    * 新增员工数据
    * */
    @Options(useGeneratedKeys = true,keyProperty = "id") //获取主键的值并赋给id属性
    @Insert("insert into emp values (null,#{username},#{password},#{name},#{gender},#{phone}," +
            "#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);


    /*
     * 批量删除员工信息
     * */
    //@Delete("delete from emp where id in (1,2,3)")
    //基于XML开发 -- 动态sql - foreach
    void deleteBatch(Integer[] ids);

    /*
    * 根据id查询员工基本信息以及员工的工作经历
    * */
    //@Select("select * from emp e left join emp_expr ee on e.id = ee.emp_id where e.id = #{id}")
    Emp getById(Integer id);

    @Select("select * from emp where id = #{id}")
    Emp getById2(Integer id);


    /*
    * 更新员工 ---动态SQL
    * */
    void update(Emp emp);


    /*
    * 统计各个职位的员工人数
    * */
    @MapKey("pos")
    List<Map<String, Object>> countEmpJobData();

    /*
    * 统计员工性别信息
    * */
    @MapKey("name")
    List<Map> countEmpGenderData();

    /*
    * 根据用户名和密码查询员工--登录
    * */
    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp selectUsernameAndPassword(Emp emp);
}
